<template>
  <el-form
    :model="noticForm"
    ref="noticForm"
    label-width="20px"
    :inline="true"
    :rules="rules"
  >
    <el-card>
      <h4 style="font-weight: 800">原订单款式</h4>
      <!-- <el-col :span="20"> -->
      <el-row v-for="(noticItem, index) in noticForm.noticConfig" :key="index">
        <el-col
          :span="24"
          v-for="nameItem in noticItem.name"
          :key="nameItem.key"
        >
          <el-form-item prop="productNo" label=" ">
            <!-- <el-input v-model="nameItem.productNo"></el-input> -->
            <el-select
              v-model="nameItem.origproductNo"
              clearable
              filterable
              remote
              :remote-method="getDatas"
              :loading="loading"
              placeholder="合作款式"
              @change="testAdd(nameItem.productNo, nameItem.id)"
              style="width: 150px"
              :disabled="true"
            >
              <el-option
                v-for="item in options"
                :key="item"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="colorProperty" label=" ">
            <!-- <el-input v-model="nameItem.colorProperty"></el-input> @focus="onFocus" remote
                :remote-method="getData"-->
            <el-select
              ref="selectRef"
              v-model="nameItem.origcolorProperty"
              clearable
              filterable
              placeholder="颜色属性"
              @change="testColor"
              style="width: 200px"
              :disabled="true"
            >
              <el-option
                v-for="item in ColorLike"
                :key="item"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="size" label=" ">
            <el-select
              @focus="onFocus"
              v-model="nameItem.origsize"
              clearable
              filterable
              remote
              :remote-method="getSize"
              placeholder="尺寸"
              style="width: 100px"
              @change="testSize(nameItem.size, nameItem.id)"
              :disabled="true"
            >
              <!--    -->
              <el-option
                v-for="item in sizeList"
                :key="item.id"
                :label="item.size"
                :value="item.size"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item @focus="onFocus" prop="productNum" label=" ">
            <el-input
              v-model="nameItem.origproductNum"
              placeholder="数量"
              style="width: 100px"
              type="number"
              oninput="value=value.replace(/^0|[^0-9]/g,'')"
              @focus="testNum()"
              :disabled="true"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              size="mini"
              @click="addDomain(noticItem, nameItem.origproductNo)"
              >换</el-button
            >
          </el-form-item>
          <el-form-item prop="productNo" label="">
            <!-- <el-input v-model="nameItem.productNo"></el-input> -->
            <el-select
              @focus="testproductNo(nameItem.origproductNo)"
              v-show="nameItem.isopen"
              v-model="nameItem.productNo"
              clearable
              filterable
              placeholder="合作款式"
              style="width: 150px"
              @change="testcolorProperty(nameItem)"
            >
              <el-option
                v-for="item in newproductNoList"
                :key="item"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item prop="colorProperty" label="">
            <!-- <el-input v-model="nameItem.colorProperty"></el-input> @focus="onFocus" remote
                :remote-method="getData"  @focus="testcolorProperty(nameItem.productNo)"-->
            <el-select
              v-show="nameItem.isopen"
              ref="selectRef"
              v-model="nameItem.colorProperty"
              clearable
              filterable
              placeholder="颜色属性"
              @change="testColor(nameItem)"
              style="width: 200px"
            >
              <el-option
                v-for="item in ColorLike"
                :key="item"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="size" label="">
            <el-select
              v-show="nameItem.isopen"
              v-model="nameItem.size"
              clearable
              filterable
              remote
              :remote-method="getSize"
              placeholder="尺寸"
              style="width: 100px"
              @change="
                testSize(
                  nameItem.productNo,
                  nameItem.colorProperty,
                  nameItem.size,
                  nameItem.id
                )
              "
            >
              <!--    -->
              <el-option
                v-for="item in sizeList"
                :key="item.id"
                :label="item.size"
                :value="item.size"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item @focus="onFocus" prop="productNum" label=" ">
            <el-input
              @input="
                handleproductNum(nameItem.productNum, nameItem.origproductNum)
              "
              v-show="nameItem.isopen"
              v-model="nameItem.productNum"
              placeholder="数量"
              style="width: 100px"
              type="number"
              oninput="value=value.replace(/^0|[^0-9]/g,'')"
              @focus="testNum()"
            ></el-input>
          </el-form-item>
          <el-form-item
            v-show="nameItem.isopen"
            prop="num"
            label="库存量:"
            label-width="70px"
          >
            {{ sizeArr[nameItem.id] }}
          </el-form-item>
          <el-form-item>
            <el-button
              v-show="nameItem.isopen"
              type="danger"
              size="mini"
              @click="stopDomain(noticItem)"
              >删除</el-button
            >
          </el-form-item>

          <!-- <el-form-item
              prop="purchasePrice"
              label="内购单价:"
              label-width="80px"
            >
              {{ nameItem.purchasePrice }}
            </el-form-item>
            
            
          <el-col :span="4">
            <el-button type="primary" size="mini" @click="addDomain(noticItem)"
              >新增</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click.prevent="removeDomain(noticItem)"
              >删除</el-button
            > -->
          <!-- <el-button type="primary" size="mini" @click="getinventory">查询</el-button> -->
        </el-col>
      </el-row>
      <!-- </el-col>
      <el-button type="primary" size="mini" @click="handlePrice">
        计算金额
      </el-button> -->
      <!-- <el-col :span="4" v-show="openPrice">
        <span
          >产品金额:{{ juShuiTanPrice.productAmount }}<br />
          运费金额:{{ juShuiTanPrice.shippingAmount }}<br />
          汇总金额:{{ juShuiTanPrice.totalAmount }}<br
        /></span>
        {"productAmount":99.5,"shippingAmount":5.0,"totalAmount":104.5}
          当前库存量：{{ sizeArr.slice(-1) }}<br />
      </el-col> -->
    </el-card>
    <el-card>
      <!-- <h4 style="font-weight: 800">支付截图(必填)</h4> -->

      <el-row>
        <el-col :span="8">
          <el-form-item
            label="回寄地址"
            prop="returnAddress"
            label-width="90px"
          >
            <el-select v-model="contactId" ref="selectRef" style="width: 450px">
              <el-option
                v-for="item in internal_purchaseList"
                :key="item.id"
                :label="`${item.phone},${item.recipient},${item.receiverState}${item.receiverCity}${item.receiverDistrict}${item.address}`"
                :value="item.id"
              />
            </el-select>
          </el-form-item>

          <!-- <el-table :data="juShuiTanPrice">
            <el-table-column
              label="商品件数"
              align="center"
              prop="productNum"
            />
            <el-table-column
              label="商品金额汇总"
              align="center"
              prop="productAmount"
            />
            <el-table-column
              label="运费金额"
              align="center"
              prop="shippingAmount"
            />
            <el-table-column
              label="汇总金额"
              align="center"
              prop="totalAmount"
            />
          </el-table> -->
        </el-col>
        <el-col :span="16">
          <el-row :inline="true">
            <!-- <el-form-item label=" " prop="payMethod" label-width="80px">
          <el-input
            v-model="sampleTalentPay.payMethod"
            placeholder="请输入支付方式"
          />
        </el-form-item> -->
            <el-form-item
              prop="expressCompany"
              label="退货快递信息:"
              label-width="110px"
            >
              <!-- <el-input v-model="expressCompany"></el-input> -->
              <el-select
                v-model="expressCompany"
                placeholder="请选择快递公司"
                clearable
                filterable
              >
                <el-option
                  v-for="dict in dict.type.sys_jst_sample_sf"
                  :key="dict.label"
                  :label="dict.label"
                  :value="dict.label"
                />
              </el-select>
            </el-form-item>
            <el-form-item prop="expressNo" label=" ">
              <el-input v-model="expressNo" placeholder="快递单号"></el-input>
            </el-form-item>
            <el-form-item
              prop="applyReason"
              label="换货理由:"
              label-width="90px"
            >
              <el-input v-model="applyReason"></el-input>
            </el-form-item>
          </el-row>
          <!-- <el-row :inline="true">
            
          </el-row> -->
          <el-row :inline="true">
            <el-form-item
              prop="productNum"
              label="运费金额:"
              label-width="90px"
            >
              <el-input
                v-model="purchasePrice"
                placeholder="运费金额"
                style="width: 100px"
              ></el-input>
            </el-form-item>
            <el-form-item label="运费截图" label-width="90px" prop="logoUrl">
              <!-- <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                    :on-exceed="handleExceed" :on-success="handlePictureSuccess" :before-upload="beforeAvatarUpload"
                                                                                                                                    :on-preview="handlePictureCardPreview" :file-list="fileList" :on-change="changeFile2">
                                                                                                                                    <i class="el-icon-plus"></i>
                                                                                                                                </el-upload>
                                                                                                                                <el-dialog :visible.sync="dialogVisible">
                                                                                                                                    <img width="100%" v-show="imageUrl" :src="imageUrl" alt="">
                                                                                                                                                                    </el-dialog> -->
              <el-upload
                ref="uploadlogourl"
                :action="imgUpload.url"
                :headers="imgUpload.headers"
                list-type="picture-card"
                :on-change="changelogourl"
                :file-list="filelogourl"
                multiple
                :on-success="uploadlogourl"
                :on-remove="Removelogourl"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <div id="preview" @paste="handlelogourl">
                <span
                  ><i class="el-icon-s-opportunity" style="color: #fb894c"></i
                  >点击此处 将图片按Ctrl+V 粘贴至此处</span
                >
              </div>
            </el-form-item>
          </el-row>

          <!-- <el-form-item label="支付账号" prop="payAccount" label-width="80px">
          <el-input
            v-model="sampleTalentPay.payAccount"
            placeholder="请输入支付账号"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="payName" label-width="60px">
          <el-input
            v-model="sampleTalentPay.payName"
            placeholder="请输入姓名"
          />
        </el-form-item> -->
        </el-col>
      </el-row>
    </el-card>

    <el-form-item style="width: 100%; text-align: center">
      <!-- <el-button @click="submitnote('noticForm')" type="primary"
        >笔记合作</el-button
      > -->
      <el-button @click="submitlive('noticForm')" type="primary"
        >申请换货</el-button
      >
      <!-- <el-button @click="resetForm" style="margin-left: 10px"
        >一键清空</el-button
      > -->
    </el-form-item>
  </el-form>
</template>
<script>
//数据获取
import { pcaa } from "area-data";
import axios from "axios";
const util = require("@/api/sample/util.js");
import { getApplyReason } from "@/api/internal/apply";
import {
  listInternalOrder,
  getInternalOrder,
  delInternalOrder,
  addInternalOrder,
  updateInternalOrder,
  startApply,
  submitApply,
  exportExcel,
  startApplyFlow,
  checkDingdingStatus,
  myList,
  addComment,
  getOrderDetails,
} from "@/api/internal/internalOrder";
import {
  listTemplate,
  getTemplate,
  delTemplate,
  addTemplate,
  updateTemplate,
  addTemplateAndSecondry,
  addProNoColorSize,
  productNoLike,
} from "@/api/product/template";
import {
  listSecondry,
  getSecondry,
  delSecondry,
  addSecondry,
  updateSecondry,
  getInfoByName,
  productNoColorLike,
  listAll,
  colorLike,
} from "@/api/product/secondry";
import {
  listSample,
  getSample,
  delSample,
  addSample,
  updateSample,
  SampleTalentFirstAdd,
  inventory,
  getSizeList,
} from "@/api/sample/sample";
import {
  listInternal_purchase,
  getInternal_purchase,
  delInternal_purchase,
  addInternal_purchase,
  updateInternal_purchase,
  getSalepriceByProductno,
  calcTotalAmount,
  addApply,
  exchangeApply,
  spuListByItemSpu,
} from "@/api/internal/internal_purchase";

//--------导入token
import { getToken } from "@/utils/auth";
export default {
  name: "Ceshi",
  dicts: [
    "sys_product_qudao",
    "sys_product_size",
    "sys_product_coder",
    "sys_sample_sf",
    "sys_one_zero",
    "sys_sample_status",
    "sys_sample_name",
    "sys_sample_cj",
    "sys_jst_sample_sf",
  ],
  props: {
    OrderDetailsList: {
      type: Array,
      default: () => [],
    },
    ids: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      newproductNoList: [],
      contactId: "",
      purchasePrice: "5",
      expressNo: "",

      internal_purchaseList: [],
      applyReason: "",

      logoUrl: "",
      filelogourl: [],
      upload_logourl: [], //提交的图片数组
      //图片相对路径
      // picurl: '',
      // //图片地址
      // picUrl: '',
      //logo相对路径
      // logoUrl: '',
      pjtUrl: process.env.VUE_APP_BASE_API,
      // 图片数量限制
      limit: 2,

      dialogVisible: false,
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },

      //聚水潭响应
      openPrice: false,
      juShuiTanPrice: [],

      count: 1,
      sizeArr: [],
      //库存量
      num: "",
      demo: "",
      //省市区
      pcaaData: pcaa,
      // 区域数据
      provinces: pcaa["86"],
      citys: [],
      areas: [],
      //
      productNo: "",
      colorProperty: "",
      size: "",
      // 遮罩层
      loading: true,
      //模糊匹配
      sizeList: [],
      ColorLike: [],
      options: [], // 选项，从后端传递过来
      sampleTalentCooperateType: "",
      expressCompany: "中通快递",
      //data
      noticForm: {
        noticConfig: [
          //   {
          //     name: [
          //       {
          //         // value: "",
          //         // phone: "",
          //         productNo: "",
          //         colorProperty: "",
          //         size: "",
          //         productNum: "",
          //         id: 0,
          //         purchasePrice: "",
          //         // expressCompany: "",
          //       },
          //     ],
          //     // phone: [
          //     //     {
          //     //         value: "",
          //     //     },
          //     // ],
          //   },
        ],
      },

      sampleTalentContact: {
        phone: "",
        receiverCity: "",
        receiverDistrict: "",
        receiverState: "",
        recipient: "",
        address: "",
      },
      sampleTalentInfo: {
        platform: "",
        platformId: "",
        talentLevel: "",
        xhsNickname: "",
        contactPerson: "",
        recommendSituation: "",
        reason: "",
        homeLink: "",
        fansNum: "",
        likeNum: "",
        cooperatePrice: "",
        talentStatus: "",
        contactWechat: "",
      },
      sampleTalentPay: {
        payAccount: "",
        payImage: "",
        payMethod: "",
        payName: "",
        platform: "",
      },

      // 表单校验
      rules: {
        productNo: [
          { required: true, message: "货号不能为空", trigger: "blur" },
        ],
        colorProperty: [
          { required: true, message: "颜色不能为空", trigger: "blur" },
        ],
        size: [{ required: true, message: "尺寸不能为空", trigger: "blur" }],
        // expressNo: [
        //   { required: true, message: "快递单号不能为空", trigger: "blur" },
        // ],
        // productNum: [
        //     { required: true, message: "数量不能为空", trigger: "blur" }
        // ],
        // platform: [
        //     { required: true, message: "平台名称不能为空", trigger: "blur" }
        // ],
        // platformId: [
        //     { required: true, message: "平台ID不能为空", trigger: "blur" }
        // ],
        // xhsNickname: [
        //     { required: true, message: "昵称不能为空", trigger: "blur" }
        // ],
        // phone: [
        //     { required: true, message: "电话不能为空", trigger: "blur" }
        // ],
      },
    };
  },
  created() {
    //获取数据
    this.gatData();
    // this.provincearr = province
    this.getList();
    // getApplyReason().then((response) => {
    //   this.applyReason = response.msg;
    // });
  },
  mounted() {
    // 自动展开下拉框
    this.$refs.selectRef.toggleMenu();
  },

  methods: {
    testproductNo(key) {
      spuListByItemSpu({ spu: key }).then((response) => {
        this.newproductNoList = response;
      });
    },
    handleproductNum(value, origproductNum) {
      console.log(origproductNum);
      console.log(value);
      if (value > origproductNum) {
        this.$modal.msgError("换货的数量不能大于原始订单的数量");
      }
    },
    gatData() {
      // getOrderDetails(this.ids).then((response) => {
      //   console.log(JSON.stringify(response.data));
      //   response.data
      this.OrderDetailsList.forEach((item) => {
        this.noticForm.noticConfig.push({
          name: [
            {
              // value: "",

              // phone: "",
              orderID: this.ids[0],
              origApplyId: item.id,
              origproductNo: item.productNo,

              origcolorProperty: item.colorProperty,
              origsize: item.productSize,
              origproductNum: item.productNum,

              isopen: false,
              productNo: item.productNo,

              colorProperty: "",
              size: "",
              productNum: "",

              // purchasePrice: "",
              // isReturn: this.noticForm.noticConfig[0].name[0].isReturn,
              id: this.count++,
              // num: "",
              // expressCompany: "",
              key: Date.now(),
            },
          ],
        });
      });
      // });
    },
    // addText() {
    //   if (!this.demo) {
    //     this.$modal.msgError("请输入内容");
    //     return;
    //   }

    //   let address = this.demo.replace(/\s+/g, " ");
    //   console.log(JSON.stringify(address));
    //   axios({
    //     method: "get",
    //     url: "https://v.api.aa1.cn/api/api-kdjx/index.php",
    //     params: {
    //       msg: address,
    //     },
    //   }).then((res) => {
    //     console.log(JSON.stringify(res.data));
    //     let m = res.data.newslist[0];
    //     this.sampleTalentContact.phone = m.mobile ? m.mobile : "";
    //     this.sampleTalentContact.recipient = m.name ? m.name : "";
    //     this.sampleTalentContact.receiverState = m.province ? m.province : "";
    //     this.sampleTalentContact.receiverCity = m.city ? m.city : "";
    //     this.sampleTalentContact.receiverDistrict = m.district
    //       ? m.district
    //       : "";
    //     this.sampleTalentContact.address = m.detail;

    //     this.seletekey(this.sampleTalentContact.receiverState, "province");
    //     this.seletekey(this.sampleTalentContact.receiverCity, "city");
    //     this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
    //   });
    // },
    /** 查询 达人信息-联系方式列表 */
    getList() {
      //   this.loading = true;
      listInternal_purchase(this.queryParams).then((response) => {
        this.internal_purchaseList = response.rows;
        // this.contactId = response.rows[response.rows.length - 1].id;
        // this.total = response.total;
        // this.loading = false;
      });
    },
    addText() {
      if (!this.demo) {
        this.$modal.msgError("请输入内容");
        return;
      }

      let address = this.demo.replace(/\s+/g, " ");
      console.log(JSON.stringify(address));
      axios({
        method: "post",
        url: "https://wangzc.wang/smAddress",
        // url: "http://47.97.123.182:1399/smAddress",
        data: {
          address: address,
        },
      }).then((res) => {
        this.sampleTalentContact.phone = res.data.phone ? res.data.phone : "";
        this.sampleTalentContact.recipient = res.data.name ? res.data.name : "";
        this.sampleTalentContact.receiverState = res.data.province
          ? res.data.province
          : "";
        this.sampleTalentContact.receiverCity = res.data.city
          ? res.data.city
          : "";
        this.sampleTalentContact.receiverDistrict = res.data.county
          ? res.data.county
          : "";
        this.sampleTalentContact.address = res.data.street
          ? res.data.street + res.data.address
          : res.data.address;

        this.seletekey(this.sampleTalentContact.receiverState, "province");
        this.seletekey(this.sampleTalentContact.receiverCity, "city");
        this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
      });
    },
    testsampleTalentCooperateType(val) {
      console.log(val);
      this.sampleTalentCooperateType = val;
    },
    //计算金额
    handlePrice() {
      if (!this.productNo) {
        this.$modal.msgError("请选择数量后计算");
        return;
      }
      this.juShuiTanPrice = [];
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      const totalCount = apply.reduce((accumulator, currentItem) => {
        if (!currentItem.productNum) {
          this.$modal.msgError("检查数量是否为空");
          return;
        }
        return accumulator + parseFloat(currentItem.productNum);
      }, 0); // 初始值设为0
      if (totalCount > 3) {
        this.$modal.msgError("请选择商品件数小于3件");
        return;
      }
      calcTotalAmount({ internalPurchaseApplyItemVoList: apply }).then(
        (response) => {
          this.juShuiTanPrice.push(response);
          this.openPrice = true;
        }
      );
    },
    /***
     * 因为提交不要冗余的数据，默认有一个列表，
     * 点击换货会追加到第二个列表，改之前判断第一个列表，改之后判断是第二个列表
     * *** */
    submitlive() {
      // console.log(JSON.stringify(this.contactId));
      // return;
      // if (!this.sampleTalentInfo.platform) {
      //   this.$modal.msgError("请输入平台名称");
      //   return;
      // }
      // if (!this.sampleTalentInfo.platformId) {
      //   this.$modal.msgError("请输入平台ID");
      //   return;
      // }
      // if (!this.sampleTalentInfo.xhsNickname) {
      //   this.$modal.msgError("请输入昵称");
      //   return;
      // }
      // if (!this.sampleTalentContact.phone) {
      //   this.$modal.msgError("请输入电话");
      //   return;
      // }
      // if (!this.sampleTalentContact.recipient) {
      //   this.$modal.msgError("请输入收件人");
      //   return;
      // }
      // if (!this.sampleTalentContact.receiverState) {
      //   this.$modal.msgError("请选择省份");
      //   return;
      // }
      // if (!this.sampleTalentContact.receiverCity) {
      //   this.$modal.msgError("请选择城市");
      //   return;
      // }
      // if (!this.sampleTalentContact.receiverDistrict) {
      //   this.$modal.msgError("请选择县区");
      //   return;
      // }
      if (!this.contactId) {
        this.$modal.msgError("请选择回寄地址");
        return;
      }
      if (!this.expressNo) {
        this.$modal.msgError("请输入快递单号");
        return;
      }
      if (!this.logoUrl) {
        this.$modal.msgError("请上传支付截图");
        return;
      }

      // == 'live'
      console.log(this.sampleTalentCooperateType);
      // if (!this.sampleTalentCooperateType.includes('live')) {
      //     this.$modal.msgError('请选择直播类型')
      //     return
      // }
      // return
      console.log(JSON.stringify(this.noticForm.noticConfig));

      // this.noticForm.noticConfig.forEach(item => {
      //     note.push(item.name)
      // })
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);

      //   const totalCount = apply.reduce((accumulator, currentItem) => {
      //     if (!currentItem.productNum) {
      //       this.$modal.msgError("检查数量是否为空");
      //       return;
      //     }
      //     return accumulator + parseFloat(currentItem.productNum);
      //   }, 0); // 初始值设为0
      //   if (totalCount > 3) {
      //     this.$modal.msgError("请选择商品件数小于3件");
      //     return;
      //   }
      var live = [];
      apply.forEach((item) => {
        if (item.isopen == true) {
          live.push({
            contactId: this.contactId,
            purchasePrice: this.purchasePrice,
            expressNo: this.expressNo,
            applyReason: this.applyReason,
            contactId: this.contactId,
            paymentUrl: this.logoUrl,
            expressCompany: this.expressCompany,
            // ...item,
            orderID: this.ids[0],
            origApplyId: item.origApplyId,
            productNo: item.productNo ? item.productNo : item.origproductNo,
            colorProperty: item.colorProperty,
            size: item.size,
            productNum: item.productNum,
          });
        }
      });
      if (live.length > 0) {
        const hasEmptyProductNo = live.some(
          (product) => product.productNo == ""
        );
        if (hasEmptyProductNo) {
          this.$modal.msgError("检查货号编码是否为空");
          return;
        }
        const hasEmptycolorProperty = live.some(
          (product) => product.colorProperty == ""
        );
        if (hasEmptycolorProperty) {
          this.$modal.msgError("检查颜色属性是否为空");
          return;
        }
        const hasEmptysize = live.some((product) => product.size == "");
        if (hasEmptysize) {
          this.$modal.msgError("检查尺寸是否为空");
          return;
        }
        const hasEmptyProductNum = live.some(
          (product) => product.productNum == ""
        );
        if (hasEmptyProductNum) {
          this.$modal.msgError("检查数量是否为空");
          return;
        }
      } else {
        this.$modal.msgError("没有选择换货");
        return;
      }

      console.log(JSON.stringify(live));
      var liveList = {
        internalPurchaseApplyItemVoList: live,
      };
      // if (!liveList.sampleTalentApplyVOList[0].productNo) {
      //   this.$modal.msgError("请选择款式");
      //   return;
      // }

      // if (!liveList.internalPurchaseApplyItemVoList[0].colorProperty) {
      //   this.$modal.msgError("请选择颜色");
      //   return;
      // }
      // if (!liveList.internalPurchaseApplyItemVoList[0].size) {
      //   this.$modal.msgError("请选择尺寸");
      //   return;
      // }
      // if (!liveList.internalPurchaseApplyItemVoList[0].productNum) {
      //   this.$modal.msgError("请输入数量");
      //   return;
      // }
      // if (liveList.internalPurchaseApplyItemVoList[1]) {
      //   if (!liveList.internalPurchaseApplyItemVoList[1].colorProperty) {
      //     this.$modal.msgError("请选择颜色");
      //     return;
      //   }
      //   if (!liveList.internalPurchaseApplyItemVoList[1].size) {
      //     this.$modal.msgError("请选择尺寸");
      //     return;
      //   }
      //   if (!liveList.internalPurchaseApplyItemVoList[1].productNum) {
      //     this.$modal.msgError("请输入数量");
      //     return;
      //   }
      // }
      // if (liveList.internalPurchaseApplyItemVoList[2]) {
      //   if (!liveList.internalPurchaseApplyItemVoList[2].colorProperty) {
      //     this.$modal.msgError("请选择颜色");
      //     return;
      //   }
      //   if (!liveList.internalPurchaseApplyItemVoList[2].size) {
      //     this.$modal.msgError("请选择尺寸");
      //     return;
      //   }
      //   if (!liveList.internalPurchaseApplyItemVoList[2].productNum) {
      //     this.$modal.msgError("请输入数量");
      //     return;
      //   }
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      // if (liveList.sampleTalentApplyVOList[1]) {
      //   if (!liveList.sampleTalentApplyVOList[1].productNo) {
      //     this.$modal.msgError("请选择第二个款式");
      //     return;
      //   }
      // }

      // return
      console.log(JSON.stringify(liveList));
      exchangeApply(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          // this.data = {};
          // window.location.reload();
          //清空数据
          this.resetForm();
          this.$emit("handleColse", "");
          //   this.$router.push({
          //     path: "/internal/internalOrder",
          //     // query: { platformId: this.sampleTalentInfo.platformId },
          //   });
          // location.reload();
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    resetForm() {
      this.noticForm = {
        noticConfig: [
          {
            name: [
              {
                productNo: "",
                colorProperty: "",
                size: "",
                productNum: "",
                purchasePrice: "",
                id: 0,
              },
            ],
          },
        ],
      };
      this.sampleTalentContact = {};
      this.sampleTalentInfo = {};
      this.sampleTalentPay = {};
    },
    submitnote() {
      if (!this.sampleTalentInfo.platform) {
        this.$modal.msgError("请输入平台名称");
        return;
      }
      if (!this.sampleTalentInfo.platformId) {
        this.$modal.msgError("请输入平台ID");
        return;
      }
      if (!this.sampleTalentInfo.xhsNickname) {
        this.$modal.msgError("请输入昵称");
        return;
      }
      if (!this.sampleTalentContact.phone) {
        this.$modal.msgError("请输入电话");
        return;
      }
      if (!this.sampleTalentContact.recipient) {
        this.$modal.msgError("请输入收件人");
        return;
      }
      if (!this.sampleTalentContact.receiverState) {
        this.$modal.msgError("请选择省份");
        return;
      }
      if (!this.sampleTalentContact.receiverCity) {
        this.$modal.msgError("请选择城市");
        return;
      }
      if (!this.sampleTalentContact.receiverDistrict) {
        this.$modal.msgError("请选择县区");
        return;
      }
      if (!this.sampleTalentContact.address) {
        this.$modal.msgError("请输入详细地址");
        return;
      }

      // if (!this.sampleTalentPay.payMethod) {

      // this.$modal.msgError('请输入支付方式')
      // return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      // this.$modal.msgError('请输入支付方式')
      // return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      //     this.$modal.msgError('请输入支付方式')
      //     return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      //     this.$modal.msgError('请输入支付方式')
      //     return
      // }
      // if (!this.sampleTalentCooperateType.includes('note')) {
      //     this.$modal.msgError('请选择笔记类型')
      //     return
      // }
      // var apply = this.noticForm.noticConfig.map(item => item.name[0])
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      console.log(JSON.stringify(apply));
      var live = [];
      apply.forEach((item) => {
        live.push({
          applyReason: this.applyReason,
          expressCompany: this.expressCompany,
          ...item,
        });
      });

      var liveList = {
        sampleTalentCooperateType: "note",
        sampleTalentApplyVOList: live,
        sampleTalentContact: { ...this.sampleTalentContact },
        sampleTalentInfo: { ...this.sampleTalentInfo },
        sampleTalentPay: { ...this.sampleTalentPay },
      };
      console.log(JSON.stringify(liveList));
      if (!liveList.sampleTalentApplyVOList[0].productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      if (liveList.sampleTalentApplyVOList[1]) {
        if (!liveList.sampleTalentApplyVOList[1].productNo) {
          this.$modal.msgError("请选择第二个款式");
          return;
        }
      }
      // return
      SampleTalentFirstAdd(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          this.$router.push({
            path: "/sample/sample",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },

    // 新增
    removeDomain(item) {
      var index = this.noticForm.noticConfig.indexOf(item);
      if (index == "0") {
        // 还有一个的时候提示不能删除
        this.$message({
          message: "不能删除了",
          type: "error",
        });
        return false;
      }
      if (index !== -1 && index !== "0") {
        this.noticForm.noticConfig.splice(index, 1);
      }
    },
    testcolorProperty(nameItem) {
      nameItem.colorProperty = "";
      nameItem.size = "";
      nameItem.productNum = "";
      productNoColorLike({ productNo: nameItem.productNo }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
    },
    // 表单新增
    stopDomain(item) {
      item.name[0].isopen = false;
      this.$forceUpdate();
      console.log(JSON.stringify(item));
    },
    // 表单新增
    addDomain(item, productNo) {
      item.name[0].isopen = true;
      this.$forceUpdate();
      console.log(JSON.stringify(item));
      this.productNo = productNo;
      productNoColorLike({ productNo: productNo }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
      getSizeList().then((response) => {
        response.forEach((item, index) => {
          this.sizeList.push({ id: index, size: item });
        });
      });
      return;
      console.log(
        JSON.stringify(this.noticForm.noticConfig[0].name[0].isReturn)
      );
      var m = item.name[0];
      if (!m.productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!m.colorProperty) {
      //   this.$modal.msgError("请选择颜色");
      //   return;
      // }
      // if (!m.size) {
      //   this.$modal.msgError("请选择尺寸");
      //   return;
      // }
      // if (!m.productNum) {
      //   this.$modal.msgError("请输入数量");
      //   return;
      // }
      // if (!m.isReturn) {
      //   this.$modal.msgError("请选择是否归还");
      //   return;
      // }
      // var i = 0
      // if(m.isReturn){

      // }
      this.noticForm.noticConfig.push({
        name: [
          {
            // value: "",

            // phone: "",
            productNo: "",
            colorProperty: "",
            size: "",
            productNum: "",
            purchasePrice: "",
            // isReturn: this.noticForm.noticConfig[0].name[0].isReturn,
            id: this.count++,
            // num: "",
            // expressCompany: "",
            key: Date.now(),
          },
        ],
      });
    },
    getinput() {
      console.log(JSON.stringify(this.noticForm.noticConfig));
    },
    //修改对话框
    /* 获取颜色列表 */
    getSize(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // listAll({ productNo: this.form.productNo, colorProperty: this.form.colorProperty }).then((res) => {
      //     // this.loading = false;
      //     this.sizeList = res
      //     console.log(JSON.stringify(res));
      // });
    },

    /* 获取颜色列表 */
    getData(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // colorLike(key).then((res) => {
      //     // this.loading = false;
      //     this.ColorLike = res.data;
      //     console.log(JSON.stringify(this.ColorLike));
      // });
    },
    getinventory() {
      inventory({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        size: this.form.size,
      }).then((res) => {
        // console.log(JSON.stringify(res.data));
        if (res.code == 200) {
          this.num = res.data[0].virtual_qty;
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    testNum(index) {
      // this.num = JSON.parse(localStorage.getItem("num"))
    },
    testSize(productNo, colorProperty, key, index) {
      console.log(JSON.stringify(key));
      this.size = key;
      // console.log(this.count);
      console.log(index);
      inventory({
        productNo: productNo,
        colorProperity: colorProperty,
        size: this.size,
      }).then((res) => {
        if (res.code == 200) {
          if (res.data.length > 0) {
            this.sizeArr[index] = res.data[0].publicCanUseNum;
            console.log(JSON.stringify(this.sizeArr[index]));
            console.log(JSON.stringify(this.sizeArr));
            this.$forceUpdate();
          } else {
            this.$modal.msgError("该商品编码聚水潭不存在，请核对。");
          }
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    // /* 获取尺寸列表 */
    testColor(nameItem) {
      this.colorProperty = nameItem.colorProperty;
      nameItem.size = "";
      nameItem.productNum = "";
      listAll({
        productNo: nameItem.productNo,
        colorProperty: nameItem.colorProperty,
      }).then((res) => {
        // this.loading = false;
        this.sizeList = res;
        console.log(JSON.stringify(res));
      });
    },
    /* 获取颜色列表 */
    testAdd(key, index) {
      this.productNo = key;
      console.log();
      productNoColorLike({ productNo: key }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
      getSalepriceByProductno(key).then((response) => {
        // this.sizeArr[index] = response;
        this.noticForm.noticConfig[index].name[0].purchasePrice = response;
      });
    },

    /* 获取货号列表 */
    getDatas(key) {
      console.log(JSON.stringify(key));
      this.loading = true;
      // return
      productNoLike(key).then((res) => {
        this.loading = false;
        this.options = res.data;
        console.log(JSON.stringify(this.options));
      });
    },
    //修改对话框
    //添加颜色列表获得焦点
    onFocus() {
      this.getData();

      this.getSize();
      // if (!this.form.colorProperty) {
      //     this.$selectRef.value.blur() //就是这一句，
      // }
    },
    seletekey(e, type) {
      if (e) {
        switch (type) {
          case "province":
            Object.keys(this.provinces).filter((item) => {
              if (this.provinces[item] === e) {
                this.citys = this.pcaaData[item];
              }
            });
            break;
          case "city":
            Object.keys(this.citys).filter((item) => {
              if (this.citys[item] === e) {
                this.areas = this.pcaaData[item];
              }
            });
            break;
          case "area":
            this.sampleTalentContact.receiverDistrict = e;
            this.$forceUpdate();
            break;
        }
      }
    },
    //logo图片
    handlelogourl(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      if (this.filelogourl.length >= this.limit) {
        this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); // 图片数量超出
        return;
      }
      this.$refs.uploadlogourl.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadlogourl.submit(); // 提交图片上传队列
    },
    //上传
    changelogourl(file, fileList) {
      // this.fileList = fileList
      console.log("成功", file, fileList);
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      if (fileList.length > 1) {
        this.filelogourl = fileList.slice(-1);
      }
    },
    Removelogourl(file, fileList) {
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      this.logoUrl = "";
    },

    uploadlogourl(res, file, fileList) {
      console.log(JSON.stringify(file.response.fileName));
      this.logoUrl = file.response.fileName;
    },
  },
};
</script>
public class InternalPurchaseApplyItemVo
{
    private static final long serialVersionUID = 1L;

    /** 联系地址id */
    private Long contactId;

    private String productNo;
    private String colorProperty;
    private Integer productNum;
    private String size;

    /**购买金额*/
    private Double purchasePrice;
    /** 支付截图 */
    private String paymentUrl;

    //快递公司信息
    private String expressCompany;
}

 /** 联系地址id */
    private Long contactId;   选地址后的id
    private Double purchasePrice;    运费金额
    /** 支付截图 */
    private String paymentUrl;    运费截图
    //快递公司信息
    private String expressCompany;    快递公司
    //快递单号
    private String expressNo;  快递号码
